package com.hntky.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hntky.common.Result;
import com.hntky.entity.*;
import com.hntky.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 周宇轩
 * @date 2023/5/10 16:49
 */
@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private DoctorService doctorService;

    @Autowired
    private UserService userService;

    @Autowired
    private PatientService patientService;

    @Autowired
    private SectorService sectorService;

    @Autowired
    private SickroomService sickroomService;

    @GetMapping("/example")
    public Result get() {
        Map<String, Object> map = new HashMap<>();
        map.put("x", CollUtil.newArrayList("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
        map.put("y", CollUtil.newArrayList(150, 230, 224, 218, 135, 147, 260));
        return Result.success(map);
    }

    @GetMapping("/doctor")
    public Result doctors() {
        // 查出所有的副主治医师
        QueryWrapper<Doctor> queryWrapper1 = new QueryWrapper();
        queryWrapper1.eq("dpost", "副主治医师");
        List list1 = doctorService.list(queryWrapper1);
        // 副主治医师的个数
        int fuZhuZhiDoctor = list1.size();

        // 查出所有的副主任医师
        QueryWrapper<Doctor> queryWrapper2 = new QueryWrapper();
        queryWrapper2.eq("dpost", "副主任医师");
        List list2 = doctorService.list(queryWrapper2);
        // 副主任医师的个数
        int fuZhuRenDoctor = list2.size();

        // 查出所有的主治医师
        QueryWrapper<Doctor> queryWrapper3 = new QueryWrapper();
        queryWrapper3.eq("dpost", "主治医师");
        List list3 = doctorService.list(queryWrapper3);
        // 主治医师的个数
        int zhuZhiDoctor = list3.size();

        // 查出所有的主任医师
        QueryWrapper<Doctor> queryWrapper4 = new QueryWrapper();
        queryWrapper4.eq("dpost", "主任医师");
        List list4 = doctorService.list(queryWrapper4);
        // 主任医师的个数
        int zhuRenDoctor = list4.size();

        // 查出所有的住院医师
        QueryWrapper<Doctor> queryWrapper5 = new QueryWrapper();
        queryWrapper5.eq("dpost", "住院医师");
        List list5 = doctorService.list(queryWrapper5);
        // 住院医师的个数
        int zhuYuanDoctor = list5.size();
        return Result.success(CollUtil.newArrayList(zhuZhiDoctor, fuZhuZhiDoctor, zhuRenDoctor, fuZhuRenDoctor, zhuYuanDoctor));
    }

    @GetMapping("/users")
    public Result users() {
        List<User> users = userService.list();
        return Result.success(users.size());
    }

    @GetMapping("/patients")
    public Result patients() {
        List<Patient> patients = patientService.list();
        return Result.success(patients.size());
    }

    @GetMapping("/sectors")
    public Result sectors() {
        List<Sector> sectors = sectorService.list();
        return Result.success(sectors.size());
    }

    @GetMapping("/rooms")
    public Result rooms() {
        List<Sickroom> rooms = sickroomService.list();
        return Result.success(rooms.size());
    }
}
